package com.sskj.mine;

import android.content.Context;
import android.content.Intent;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.bulong.rudeness.RudenessScreenHelper;
import com.shizhefei.mvc.MVCCoolHelper;
import com.shizhefei.view.coolrefreshview.CoolRefreshView;
import com.sskj.common.adapter.slimadapter.IViewInjector;
import com.sskj.common.adapter.slimadapter.SlimAdapter;
import com.sskj.common.adapter.slimadapter.SlimInjector;
import com.sskj.common.base.App;
import com.sskj.common.box.decoration.DividerLineItemDecoration;
import com.sskj.lib.base.BaseActivity;
import com.sskj.lib.mvchelper.ModelRx2DataSource;
import com.sskj.mine.bean.NodeBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * @author Hey
 * Create at  2019/05/10
 */
public class SuperNodeActivity extends BaseActivity<SuperNodePresenter> {

    @BindView(R2.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R2.id.coolRefreshView)
    CoolRefreshView coolRefreshView;
    private SlimAdapter slimAdapter;
    private MVCCoolHelper<List<NodeBean>> mvcHelper;

    @Override
    public int getLayoutId() {
        return R.layout.mine_activity_super_node;
    }

    @Override
    public SuperNodePresenter getPresenter() {
        return new SuperNodePresenter();
    }

    @Override
    public void initView() {
        setTitle(App.INSTANCE.getString(R.string.mine_superNodeActivity1_j));
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new DividerLineItemDecoration(this)
                .setPaintWidth((int) RudenessScreenHelper.pt2px(App.INSTANCE, 20))
                .setDividerColor(ContextCompat.getColor(App.INSTANCE, R.color.transparent))
        );
        slimAdapter = SlimAdapter.create().register(R.layout.mine_recy_item_node, new SlimInjector<NodeBean>() {
            @Override
            public void onInject(NodeBean data, IViewInjector injector, List list) {

                injector
                        .text(R.id.item_price, data.getPrice())
                        .text(R.id.item_time, data.getAddtime());
            }
        }).attachTo(recyclerView).updateData(new ArrayList());


        ModelRx2DataSource<NodeBean> dataSource = new ModelRx2DataSource<>((ModelRx2DataSource.OnLoadSource<NodeBean>)
                page -> mPresenter.getData(page + "", "20"), 20);
        mvcHelper = new MVCCoolHelper<>(coolRefreshView);
        mvcHelper.setDataSource(dataSource);
        mvcHelper.setAdapter(slimAdapter);
        mvcHelper.refresh();
    }

    @Override
    public void initData() {

    }

    public static void start(Context context) {
        Intent intent = new Intent(context, SuperNodeActivity.class);
        context.startActivity(intent);
    }

}
